package xin.marcher.module.replenished.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import xin.marcher.module.common.constants.diplomacy.AbstractRedisKeyConstants;
import xin.marcher.module.common.constants.replenished.CompensationConstants;
import xin.marcher.module.common.constants.replenished.RecoverableConstants;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.core.PageResult;
import xin.marcher.module.common.enums.lifecycle.ItemExpriEnum;
import xin.marcher.module.common.enums.seller.SellerGroupStatusEnum;
import xin.marcher.module.common.enums.seller.SellerTypeEnum;
import xin.marcher.module.lifecycle.domain.dto.ItemExpriResultDTO;
import xin.marcher.module.replenished.converter.RecoverableConverter;
import xin.marcher.module.replenished.domain.bo.ProductSellerRelationBO;
import xin.marcher.module.replenished.domain.entity.ItemProcurementConfigDO;
import xin.marcher.module.replenished.domain.entity.ProductDetailDO;
import xin.marcher.module.replenished.domain.entity.SkuSellerRelationDO;
import xin.marcher.module.replenished.domain.entity.StackSkuRelationDO;
import xin.marcher.module.replenished.domain.request.RecoverableRequest;
import xin.marcher.module.replenished.redis.RedisReadWriteManager;
import xin.marcher.module.replenished.redis.RedisSortedSetCache;
import xin.marcher.module.replenished.remote.ItemPeriodStageRemote;
import xin.marcher.module.replenished.remote.SellerRemote;
import xin.marcher.module.replenished.repository.ProductConfigRepository;
import xin.marcher.module.replenished.repository.ProductRelationRepository;
import xin.marcher.module.replenished.repository.ProductRepository;
import xin.marcher.module.replenished.repository.RedisManagerRepository;
import xin.marcher.module.replenished.service.RecoverableService;
import xin.marcher.module.seller.domain.response.SellerGroupResponse;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 商品可采业务实现类
 *
 * 
 */
@Service
public class RecoverableServiceImpl implements RecoverableService {
    @Resource
    private ProductRepository productRepository;
    @Resource
    private ProductConfigRepository productConfigRepository;
    @Resource
    private ProductRelationRepository productRelationRepository;
    @Resource
    private RedisManagerRepository redisManagerRepository;

    @Resource
    private SellerRemote sellerRemote;
    @Resource
    private ItemPeriodStageRemote itemPeriodStageRemote;
    @Resource
    private RecoverableConverter recoverableConverter;

    @Resource
    private RedisReadWriteManager redisReadWriteManager;

    /**
     * 同步可采的数据入缓存
     *
     * @param request
     * @return
     */
    @Override
    public JsonResult syncRecoverableProduct(RecoverableRequest request) {
        Integer pageNo = 1;
        // 获取卖家类型对应的卖家组信息
        List<SellerGroupResponse> sellerInfoResponseList = querySellerGroupList(pageNo, request.getSellerGroupType());
        while (!CollectionUtils.isEmpty(sellerInfoResponseList)) {
            //1. 过滤卖家组的非有效状态信息数据
            List<SellerGroupResponse> sellerGroupResponseList = sellerGroupFilter(sellerInfoResponseList);
            //2. 根据卖家组获取卖家支持的可售商品列表
            List<SkuSellerRelationDO> sellerRelationDOList = queryAvailableProduct(sellerGroupResponseList);
            //3. 查询商品信息，并过滤非自营的商品
            List<ProductDetailDO> skuInfoDOList = querySkuInfoList(sellerRelationDOList);
            //4. 进行item级别的商品过滤(无需采购和生命周期)
            List<ProductDetailDO> itemFilterList = itemFilter(skuInfoDOList);
            //5. 进行组套商品的商品过滤(无需采购和生命周期)
            List<ProductDetailDO> suitFilterList = suitFilter(itemFilterList);
            //6. 将详情的商品sku信息绑定到卖家上
            List<ProductSellerRelationBO> productSellerRelationBOList = buildBinding(sellerRelationDOList, suitFilterList);
            //7, 读取历史的缓存信息，对已经存在的缓存进行diff处理并刷入缓存
            diffRecoverableCache(productSellerRelationBOList, sellerInfoResponseList);
            pageNo++;
            sellerInfoResponseList = querySellerGroupList(pageNo, request.getSellerGroupType());
        }
        return JsonResult.buildSuccess();
    }

    /**
     * 分页查询 卖家组信息
     *
     * @param pageNo
     */
    public List<SellerGroupResponse> querySellerGroupList(Integer pageNo, Integer sellerGroupType) {
        PageResult<SellerGroupResponse> sellerGroupPage =
                sellerRemote.getSellerGroupList(pageNo, CompensationConstants.SELLER_PAGE_SIZE, sellerGroupType);
        return sellerGroupPage.getContent();
    }


    /**
     * 对卖家组状态非有效的进行过滤
     *
     * @param sellerInfoResponseList
     * @return
     */
    private List<SellerGroupResponse> sellerGroupFilter(List<SellerGroupResponse> sellerInfoResponseList) {
        // 过滤无效的卖家组信息
        return sellerInfoResponseList.stream()
                .filter(sellerGroupResponse -> SellerGroupStatusEnum.EFFECTIVE_STATUS.getCode().equals(sellerGroupResponse.getSellerGroupStatus()))
                .collect(Collectors.toList());
    }

    /**
     * 返回卖家组支持的可售商品列表
     *
     * @param sellerInfoResponseList
     */
    private List<SkuSellerRelationDO> queryAvailableProduct(List<SellerGroupResponse> sellerInfoResponseList) {
        if (!CollectionUtils.isEmpty(sellerInfoResponseList)) {
            // 转换为所有的卖家组ID
            List<Long> sellerIdSplitList = sellerInfoResponseList.stream().map(response -> response.getSellerGroupId().longValue()).collect(Collectors.toList());
            //分页批量查询 卖家组支持的可售商品列表
            return productRelationRepository.pageQueryAvailableProduct(sellerIdSplitList);
        }
        return new ArrayList<>();
    }


    /**
     * 批量查询出对应的可售自营商品详情信息
     *
     * @param sellerRelationDOList
     * @return
     */
    private List<ProductDetailDO> querySkuInfoList(List<SkuSellerRelationDO> sellerRelationDOList) {
        if (!CollectionUtils.isEmpty(sellerRelationDOList)) {
            // 先获取到对应的skuID列表
            Set<String> skuIdList = sellerRelationDOList.stream().map(SkuSellerRelationDO::getSkuId).collect(Collectors.toSet());
            // 一次最大查询1000 skuId，多个分页查询,这里做数据切割
            List<ProductDetailDO> productDetailDOList = productRepository.pageQueryProductInfoList(skuIdList);
            if (!CollectionUtils.isEmpty(productDetailDOList)) {
                List<ProductDetailDO> productDetailDOS = productDetailDOList.stream()
                        .filter(productDetailDO -> productDetailDO.getSellerType().equals(SellerTypeEnum.SELF.getCode()))
                        .collect(Collectors.toList());
                return productDetailDOS;
            }
        }
        return new ArrayList<>();
    }

    /**
     * 进行item级别的商品过滤(无需采购和生命周期)
     *
     * @param productDetailDOList
     */
    private List<ProductDetailDO> itemFilter(List<ProductDetailDO> productDetailDOList) {
        if (!CollectionUtils.isEmpty(productDetailDOList)) {
            //过滤掉无需采购的商品列表
            List<ProductDetailDO> productDetailList = filterPurchaseProduct(productDetailDOList);
            // 商品进行生命周期的查询检查，过滤不符合条件的商品
            return filterLifeCycle(productDetailList);
        }
        return productDetailDOList;
    }

    /**
     * 进行组套商品的商品过滤(无需采购和生命周期)
     *
     * @param productDetailList
     * @return
     */
    private List<ProductDetailDO> suitFilter(List<ProductDetailDO> productDetailList) {
        if (!CollectionUtils.isEmpty(productDetailList)) {
            //1. 查询哪些是组套商品，并且反向寻找到组套商品归属的item信息
            List<ProductDetailDO> suitItemDOList = querySuitList(productDetailList);
            //2. 过滤掉无需采购的商品列表
            List<ProductDetailDO> productDetailDOList = filterSuitPurchaseProduct(suitItemDOList);
            //3. 商品进行生命周期的查询检查，过滤不符合条件的商品
            return filterSuitLifeCycle(productDetailDOList);
        }
        return productDetailList;
    }

    /**
     * 进行商品生命周期的过滤
     *
     * @param productDetailList
     * @return
     */
    private List<ProductDetailDO> filterLifeCycle(List<ProductDetailDO> productDetailList) {
        if (!CollectionUtils.isEmpty(productDetailList)) {
            // 构建调用生命周期的接口入参模型
            Set<String> itemIdList = productDetailList.stream().map(ProductDetailDO::getItemId).collect(Collectors.toSet());
            List<ItemExpriResultDTO> skuExpriResultDTOS = itemPeriodStageRemote.queryByItemIds(itemIdList);
            // 集合转map，方便验证是否命中
            Map<String, ItemExpriResultDTO> itemExpriResultMap = skuExpriResultDTOS.stream().collect(Collectors.toMap(ItemExpriResultDTO::getItemId, Function.identity()));
            // 过滤不符合条件的商品
            List<ProductDetailDO> productDetailDOList = productDetailList.stream().filter(productDetail -> {
                // 没有命中不保留
                if (!itemExpriResultMap.containsKey(productDetail.getItemId())) {
                    return false;
                }
                ItemExpriResultDTO itemExpriResultDTO = itemExpriResultMap.get(productDetail.getItemId());
                // 可采的状态返回true
                return itemExpriResultDTO.getPurchaseStatus().equals(ItemExpriEnum.COMPENSATION_STATUS_YES.getCode());
            }).collect(Collectors.toList());
            //返回过滤后的商品信息
            return productDetailDOList;
        }
        return productDetailList;
    }

    /**
     * 过滤无需采购的item列表信息
     *
     * @param suitItemDOList
     */
    private List<ProductDetailDO> filterPurchaseProduct(List<ProductDetailDO> suitItemDOList) {
        // 获取配置的无需采购的列表
        List<ItemProcurementConfigDO> itemProcurementConfigList = productConfigRepository.queryProcurementConfigList();
        // 空集合判断
        if (CollectionUtils.isEmpty(suitItemDOList)) {
            return new ArrayList();
        }
        if (CollectionUtils.isEmpty(itemProcurementConfigList)) {
            return suitItemDOList;
        }
        // 集合转map，方便验证是否命中
        Map<Integer, ItemProcurementConfigDO> procurementConfigMap = itemProcurementConfigList.stream()
                .collect(Collectors.toMap(ItemProcurementConfigDO::getCategoryId, Function.identity()));
        //开始过滤无需采购的商品信息
        List<ProductDetailDO> productDetailDOList = suitItemDOList.stream()
                .filter(productDetail -> !procurementConfigMap.containsKey(productDetail.getCategoryId()))
                .collect(Collectors.toList());
        //返回过滤后的商品信息
        return productDetailDOList;
    }

    /**
     * 过滤无需采购的组套商品
     *
     * @param suitItemDOList
     * @return
     */
    private List<ProductDetailDO> filterSuitPurchaseProduct(List<ProductDetailDO> suitItemDOList) {
        // 获取配置的无需采购的列表
        List<ItemProcurementConfigDO> itemProcurementConfigList = productConfigRepository.queryProcurementConfigList();
        // 空集合判断
        if (CollectionUtils.isEmpty(suitItemDOList)) {
            return new ArrayList();
        }
        if (CollectionUtils.isEmpty(itemProcurementConfigList)) {
            return suitItemDOList;
        }
        // 集合转map，方便验证是否命中
        Map<Integer, ItemProcurementConfigDO> procurementConfigMap = itemProcurementConfigList.stream().collect(Collectors.toMap(ItemProcurementConfigDO::getCategoryId, Function.identity()));
        List<ProductDetailDO> productDetailDOList = new ArrayList<>(suitItemDOList.size());
        for (ProductDetailDO productDetailDO : suitItemDOList) {
            if (productDetailDO.getProductType().equals(2)) {
                List<ProductDetailDO> productDetailList = productDetailDO.getProductDetailList();
                // 组套商品有商品不满足条件
                if (checkSuitPurchaseProduct(productDetailList, procurementConfigMap)) {
                    continue;
                }
            }
            productDetailDOList.add(productDetailDO);
        }
        return productDetailDOList;
    }

    /**
     * 进行组套商品生命周期的过滤
     *
     * @param productDetailList
     * @return
     */
    private List<ProductDetailDO> filterSuitLifeCycle(List<ProductDetailDO> productDetailList) {
        List<ProductDetailDO> productDetailDOAllList = new ArrayList<>(productDetailList.size());
        if (!CollectionUtils.isEmpty(productDetailList)) {
            // 查询返回生命周期的数据模型
            Map<String, ItemExpriResultDTO> itemExpriResultMap = queryItemExpriMap(productDetailList);
            for (ProductDetailDO productDetailDO : productDetailList) {
                if (productDetailDO.getProductType().equals(2)) {
                    List<ProductDetailDO> productDetailDOList = productDetailDO.getProductDetailList();
                    if (checkSuitLifeCycle(productDetailDOList, itemExpriResultMap)) {
                        continue;
                    }
                }
                productDetailDOAllList.add(productDetailDO);
            }
        }
        return productDetailDOAllList;
    }

    /**
     * 验证组套商品的生命周期，有一个不符合条件则过滤上级父类商品
     *
     * @param productDetailDOList
     * @param itemExpriResultMap
     * @return
     */
    private Boolean checkSuitLifeCycle(List<ProductDetailDO> productDetailDOList, Map<String, ItemExpriResultDTO> itemExpriResultMap) {
        for (ProductDetailDO productDetailDO : productDetailDOList) {
            // 没有命中不保留
            if (!itemExpriResultMap.containsKey(productDetailDO.getItemId())) {
                return true;
            }
            ItemExpriResultDTO itemExpriResultDTO = itemExpriResultMap.get(productDetailDO.getItemId());
            // 可采的状态返回true
            if (!itemExpriResultDTO.getPurchaseStatus().equals(ItemExpriEnum.COMPENSATION_STATUS_YES.getCode())) {
                return true;
            }
        }
        return false;
    }

    /**
     * 查询 商品的生命周期
     *
     * @param productDetailList
     * @return
     */
    private Map<String, ItemExpriResultDTO> queryItemExpriMap(List<ProductDetailDO> productDetailList) {
        List<ProductDetailDO> productAllList = new ArrayList<>(RecoverableConstants.SKU_INIT_NUM);
        // 汇总组套商品下搭配的全部商品信息
        for (ProductDetailDO productDetailDO : productDetailList) {
            if (productDetailDO.getProductType().equals(2)) {
                List<ProductDetailDO> productDetailDoList = productDetailDO.getProductDetailList();
                productAllList.addAll(productDetailDoList);
            }
        }

        Set<String> itemIdList = productAllList.stream().map(ProductDetailDO::getItemId).collect(Collectors.toSet());
        List<ItemExpriResultDTO> skuExpriResultDTOS = itemPeriodStageRemote.queryByItemIds(itemIdList);
        // 集合转map，方便验证是否命中
        Map<String, ItemExpriResultDTO> itemExpriResultMap = skuExpriResultDTOS.stream().collect(Collectors.toMap(ItemExpriResultDTO::getItemId, Function.identity()));

        return itemExpriResultMap;
    }

    /**
     * 验证组套商品是否无需过滤
     *
     * @param suitItemDOList
     * @param procurementConfigMap
     * @return
     */
    private Boolean checkSuitPurchaseProduct(List<ProductDetailDO> suitItemDOList, Map<Integer, ItemProcurementConfigDO> procurementConfigMap) {
        if (!CollectionUtils.isEmpty(suitItemDOList)) {
            for (ProductDetailDO productDetailDO : suitItemDOList) {
                if (procurementConfigMap.containsKey(productDetailDO.getCategoryId())) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 进行 数据去除过滤处理
     *
     * @param productAllList 全量数据集合
     * @param diffFailList   差异数据对象
     * @param isAnode        true 返回 全量和差异集合的差异数据，false 全量过滤掉差异数据集合
     * @return
     */
    private List<ProductDetailDO> diffProductList(List<ProductDetailDO> productAllList, List<ProductDetailDO> diffFailList, boolean isAnode) {
        // 作为接下来校验差异的比较条件
        Map<String, ProductDetailDO> productDetailDOMap = diffFailList.stream().collect(Collectors.toMap(ProductDetailDO::getSkuId, Function.identity()));
        // 返回差异数据
        if (isAnode) {
            List<ProductDetailDO> diffProductList = productAllList.stream()
                    .filter(productDetailDO -> !productDetailDOMap.containsKey(productDetailDO.getSkuId()))
                    .collect(Collectors.toList());
            // 填充卖家的不可售商品列表
            return diffProductList;
        } else {
            // 删除差异数据(命中的都是不可售商品)
            List<ProductDetailDO> diffProductList = productAllList.stream()
                    .filter(productDetailDO -> productDetailDOMap.containsKey(productDetailDO.getSkuId()))
                    .collect(Collectors.toList());
            // 填充卖家的可售商品列表
            return diffProductList;
        }
    }

    /**
     * 通过商品明细，查询出哪些是组套商品，并输出对应的归属item数据结构
     *
     * @param skuInfoDOList
     */
    private List<ProductDetailDO> querySuitList(List<ProductDetailDO> skuInfoDOList) {
        // 根据skuId 批量查询是否组套商品
        List<StackSkuRelationDO> stackSkuRelationAllList = queryStackSkuListByIds(skuInfoDOList);
        // 没有组套商品的直接返回
        if (CollectionUtils.isEmpty(stackSkuRelationAllList)) {
            return skuInfoDOList;
        }
        // 返回组套商品的详情集合信息(包含item信息)
        List<ProductDetailDO> itemProductList = queryProductInfoList(stackSkuRelationAllList);
        // 将组套商品绑定到上级对应商品下
        return buildSuitBinding(itemProductList, skuInfoDOList, stackSkuRelationAllList);
    }

    /**
     * 将组套商品绑定上
     *
     * @param itemProductList
     * @param skuInfoDOList
     * @param stackSkuRelationAllList
     * @return
     */
    private List<ProductDetailDO> buildSuitBinding(List<ProductDetailDO> itemProductList, List<ProductDetailDO> skuInfoDOList, List<StackSkuRelationDO> stackSkuRelationAllList) {
        List<ProductDetailDO> productSellerRelationBOList = recoverableConverter.converterProductList(skuInfoDOList);
        // sku对应的组套商品详情(对应组套商品的stackSkuId)
        Map<String, ProductDetailDO> productDetailMap = itemProductList.stream().collect(Collectors.toMap(ProductDetailDO::getSkuId, Function.identity()));
        //组套的商品集合(一个商品下多个物料sku组装而成)
        Map<String, List<StackSkuRelationDO>> stackSkuRelationMap = stackSkuRelationAllList.stream().collect(Collectors.groupingBy(StackSkuRelationDO::getSkuId));
        for (ProductDetailDO productDetailDO : productSellerRelationBOList) {
            // 命中到了对应的组套商品
            if (stackSkuRelationMap.containsKey(productDetailDO.getSkuId())) {
                // 标记为组套商品
                productDetailDO.setProductType(2);
                // 同时存储对应的组套商品详情信息
                List<StackSkuRelationDO> stackSkuRelationList = stackSkuRelationMap.get(productDetailDO.getSkuId());
                List<ProductDetailDO> productDetailDOS = new ArrayList<>();
                for (StackSkuRelationDO stackSkuRelationDO : stackSkuRelationList) {
                    if (productDetailMap.containsKey(stackSkuRelationDO.getStackSkuId())) {
                        ProductDetailDO productDetail = productDetailMap.get(stackSkuRelationDO.getStackSkuId());
                        productDetailDOS.add(productDetail);
                    }
                }
                productDetailDO.setProductDetailList(productDetailDOS);
            }
        }
        return productSellerRelationBOList;
    }

    /**
     * 根据skuId 批量查询是否组套商品
     *
     * @param skuInfoDOList
     * @return
     */
    private List<StackSkuRelationDO> queryStackSkuListByIds(List<ProductDetailDO> skuInfoDOList) {
        // 先获取到对应的skuID列表
        Set<String> skuIdList = skuInfoDOList.stream().map(ProductDetailDO::getSkuId).collect(Collectors.toSet());

        return productRelationRepository.pageQueryStackSkuListByIds(skuIdList);
    }

    /**
     * 获取组套商品的详情集合信息
     *
     * @param stackSkuRelationAllList
     * @return
     */
    private List<ProductDetailDO> queryProductInfoList(List<StackSkuRelationDO> stackSkuRelationAllList) {
        // 获取组套商品的sku列表，通过sku列表联合查询得到对应的item信息
        Set<String> stackSkuIdList = stackSkuRelationAllList.stream().map(StackSkuRelationDO::getStackSkuId).collect(Collectors.toSet());
        //查询组套商品详情集合信息
        return productRepository.pageQueryProductInfoList(stackSkuIdList);
    }

    /**
     * 将sku商品明细 绑定到卖家上
     *
     * @param sellerRelationDOList
     * @param skuInfoDOList
     * @return
     */
    private List<ProductSellerRelationBO> buildBinding(List<SkuSellerRelationDO> sellerRelationDOList, List<ProductDetailDO> skuInfoDOList) {
        // 先转换集合为map，key为商品的skuId标识
        Map<String, ProductDetailDO> skuInfoDOMap = skuInfoDOList.stream().collect(Collectors.toMap(ProductDetailDO::getSkuId, Function.identity()));
        // 按卖家ID进行分组，把下属的商品合并到一个上
        Map<Long, List<SkuSellerRelationDO>> skuSellerRelationMap = sellerRelationDOList.stream().collect(Collectors.groupingBy(SkuSellerRelationDO::getSellerGroupId));
        // 返回的绑定卖家和商品sku的集合对象
        List<ProductSellerRelationBO> sellerRelationBOList = new ArrayList<>(sellerRelationDOList.size());
        // 遍历 卖家和商品关系集合，开始填充商品sku信息绑定到卖家组上
        for (Map.Entry<Long, List<SkuSellerRelationDO>> entry : skuSellerRelationMap.entrySet()) {
            List<SkuSellerRelationDO> skuSellerRelationDOS = entry.getValue();
            Long sellerGroupId = entry.getKey();
            // 循环绑定卖家组下的商品关系
            ProductSellerRelationBO skuSellerRelationBO = new ProductSellerRelationBO();
            skuSellerRelationBO.setSellerId(sellerGroupId);
            List<ProductDetailDO> productDetailList = new ArrayList<>();
            // 遍历卖家组下的可售商品列表
            for (SkuSellerRelationDO sellerRelationDO : skuSellerRelationDOS) {
                // 查询的数据集合中 存在这个商品数据
                if (skuInfoDOMap.containsKey(sellerRelationDO.getSkuId())) {
                    ProductDetailDO productDetailDO = skuInfoDOMap.get(sellerRelationDO.getSkuId());
                    // 绑定数据到卖家组上
                    productDetailList.add(productDetailDO);
                }
            }
            skuSellerRelationBO.setProductDetailList(productDetailList);
            sellerRelationBOList.add(skuSellerRelationBO);
        }
        return sellerRelationBOList;
    }

    /**
     * 对 已经缓存的历史数据进行diff处理，处理缓存 缓存变更
     *
     * @param productSellerRelationBOList 变更数据对象
     * @param sellerInfoResponseList      查询的初始对象
     * @return
     */
    private void diffRecoverableCache(List<ProductSellerRelationBO> productSellerRelationBOList,
                                      List<SellerGroupResponse> sellerInfoResponseList) {
        //1. 获取卖家组ID集合
        Set<Long> sellerIdList = sellerInfoResponseList.stream().map(response -> response.getSellerGroupId().longValue()).collect(Collectors.toSet());
        //2.数据差集比较,并刷入缓存差异信息
        diffCache(sellerIdList, productSellerRelationBOList);
    }


    /**
     * 开始进行数据差集的处理
     *
     * @param sellerIdList
     * @param productSellerRelationBOList
     */
    private void diffCache(Set<Long> sellerIdList, List<ProductSellerRelationBO> productSellerRelationBOList) {
        //1.批量查询缓存
        Map<Long, List<String>> redisSetMap = redisReadWriteManager.getRedisSortedSet(sellerIdList, AbstractRedisKeyConstants::getSellerTypePurchaseSkuZsetKey);
        // 转换缓存的值为具体的对象
        Map<Long, Map<String, ProductDetailDO>> productSellerRelationBOMap = redisManagerRepository.converterProductSellerCache(redisSetMap);
        // 进行数据差集处理
        Map<String, RedisSortedSetCache> diffSortedSetCache = redisManagerRepository.diffProduct(productSellerRelationBOList, productSellerRelationBOMap, AbstractRedisKeyConstants::getSellerTypePurchaseSkuZsetKey);
        // 执行数据缓存更新
        redisReadWriteManager.flushIncrSortedSetMap(diffSortedSetCache);
    }

    /**
     * 对组套商品进行合并，将符合条件的组套商品以及非组套商品的结果集合并返回
     *
     * @param productDetailList 全部的商品信息
     * @param suitItemDOList    组套商品信息
     * @param lifeCycleList     验证成功的组套商品信息
     * @return
     */
    private List<ProductDetailDO> migrateProduct(List<ProductDetailDO> productDetailList, List<ProductDetailDO> suitItemDOList, List<ProductDetailDO> lifeCycleList) {
        //1. 从组套商品中 验证成功的组套商品差集
        List<ProductDetailDO> productDetailDOList = diffProductList(suitItemDOList, lifeCycleList, true);
        //2.将差集数据，视为不符合条件的商品从全部商品中移除并返回
        return diffProductList(productDetailList, productDetailDOList, false);
    }


}
